package com.quatrix.openphantasy.client.datasource;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.RestDataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class TeamDS extends BaseDS {
	final static String SERVICE_URL = GWT.getModuleBaseURL() + "/Proxy/TeamService";
	///////////////////////////////////////////////////////////////////////////
	// Singleton setup
	///////////////////////////////////////////////////////////////////////////
	private static TeamDS _instance;
	
	public static DataSource getInstance() {
		if (_instance == null) {
			_instance = new TeamDS();
		}
		
		return _instance;
	}
	
	///////////////////////////////////////////////////////////////////////////
	// Fields
	///////////////////////////////////////////////////////////////////////////	
	private final DataSourceField _id = new DataSourceIntegerField("id");
	private final DataSourceField _name = new DataSourceTextField("name");
	private final DataSourceField _country = new DataSourceTextField("country");
	private final DataSourceField _lastLeague = new DataSourceIntegerField("lastLeague");
	
	TeamDS() {
		super("TeamDS", SERVICE_URL);
		
		_id.setPrimaryKey(true);
		_id.setCanEdit(false);
		_country.setForeignKey("CountryDS.code");
		
		setFields(_id, _name, _country, _lastLeague);
	}
}
